package com.at.abc.r420_ak;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class e {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solve();
        out.flush();
        out.close();
        br.close();
    }

    public static int MAXN = 200005;
    public static int[] parent = new int[MAXN];
    public static int n;
    static int[] size = new int[MAXN];
    static int[] blackCount = new int[MAXN]; // 黑点的数量
    static boolean[] color = new boolean[MAXN]; // 顶点颜色：true=黑，false=白

    public static void build(int n) {
        for (int i = 1; i <= n; i++) {
            parent[i] = i;
            size[i] = 1;
            blackCount[i] = 0;
            color[i] = false;
        }
    }
    public static int find(int i) {
        if (i != parent[i]) {
            parent[i] = find(parent[i]);
        }
        return parent[i];
    }
    public static void union(int x, int y) {
        int rx = find(x), ry = find(y);
        if (rx == ry) return;
        if (size[rx] > size[ry]) {
            int tmp = rx; rx = ry; ry = tmp;
        }
        parent[rx] = ry;
        size[ry] += size[rx];
        blackCount[ry] += blackCount[rx];
    }

    static void solve() throws IOException {
        String[] in = br.readLine().split(" ");
        n = Integer.parseInt(in[0]);
        int q = Integer.parseInt(in[1]);
        build(n);

        while (q-- > 0) {
            in = br.readLine().split(" ");
            int type = Integer.parseInt(in[0]);
            if (type == 1) {
                int u = Integer.parseInt(in[1]);
                int v = Integer.parseInt(in[2]);
                union(u, v);
            } else if (type == 2) {
                int v = Integer.parseInt(in[1]);
                int root = find(v);
                if (!color[v]) {
                    color[v] = true;
                    blackCount[root] += 1;
                } else {
                    color[v] = false;
                    blackCount[root] -= 1;
                }
            } else if (type == 3) {
                int v = Integer.parseInt(in[1]);
                int root = find(v);
                if (blackCount[root] > 0) {
                    out.println("Yes");
                } else {
                    out.println("No");
                }
            }
        }
    }
}
